package com.gz.logistics.library.pojo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单详情
 * author wanner1991
 */
public class OrderDetail implements Serializable{
    private String sn ;// 订单编号
    private String create_at;//创建时间
    private String receiver_name;// 收货人姓名
    private String receiver_add;// 收货人地址
    private String receiver_tel;// 收货人电话
    private String pay_type;// 支付方式： 0在线支付，1货到付款
    private String cpucbt;// 提货方式,0送货上门，1自提
    private double money;//应收金额
    private String notes;//订单备注
    private String ostatus;//业务签收状态 1已签收，2未签收
    private String real_money;//实收金额
    private String s_key;

    public String getS_key() {
        return s_key;
    }

    public void setS_key(String s_key) {
        this.s_key = s_key;
    }

    public String getReal_money() {
        return real_money;
    }

    public void setReal_money(String real_money) {
        this.real_money = real_money;
    }

    public String getReceive_type() {
        return receive_type;
    }

    public void setReceive_type(String receive_type) {
        this.receive_type = receive_type;
    }

    private String receive_type;//收款方式
    private List<ProductInfo> productInfos;//商品信息

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getCreate_at() {
        return create_at;
    }

    public void setCreate_at(String create_at) {
        this.create_at = create_at;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public List<ProductInfo> getProductInfos() {
        return productInfos;
    }

    public void setProductInfos(List<ProductInfo> productInfos) {
        this.productInfos = productInfos;
    }

    public String getReceiver_name() {
        return receiver_name;
    }

    public void setReceiver_name(String receiver_name) {
        this.receiver_name = receiver_name;
    }

    public String getReceiver_add() {
        return receiver_add;
    }

    public void setReceiver_add(String receiver_add) {
        this.receiver_add = receiver_add;
    }

    public String getReceiver_tel() {
        return receiver_tel;
    }

    public void setReceiver_tel(String receiver_tel) {
        this.receiver_tel = receiver_tel;
    }

    public String getPay_type() {
        return pay_type;
    }

    public void setPay_type(String pay_type) {
        this.pay_type = pay_type;
    }

    public String getCpucbt() {
        return cpucbt;
    }

    public void setCpucbt(String cpucbt) {
        this.cpucbt = cpucbt;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getOstatus() {
        return ostatus;
    }

    public void setOstatus(String ostatus) {
        this.ostatus = ostatus;
    }

    private boolean isSelected;// 是否被选中

    public boolean isSelected() {
        return isSelected;
    }

    public void setIsSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }



    public static List<OrderDetail> parse(JSONArray jsonArray) throws JSONException {
        if (jsonArray == null || jsonArray.length() <= 0){
            return null;
        }
        List<OrderDetail> orderInfos = new ArrayList<OrderDetail>();
        for (int i = 0 ; i < jsonArray.length() ; i++ ){
            OrderDetail orderInfo = new OrderDetail();
            JSONObject object = jsonArray.getJSONObject(i);
            orderInfo.sn = object.getString("sn");
            orderInfo.create_at = object.getString("create_at");
            orderInfo.receiver_name = object.getString("receiver_name");
            orderInfo.receiver_add = object.getString("receiver_add");
            orderInfo.receiver_tel = object.getString("receiver_tel");
            orderInfo.pay_type = object.getString("pay_type");
            orderInfo.cpucbt = object.getString("cpucbt");
            orderInfo.money = object.getDouble("money");
            orderInfo.notes = object.getString("notes");
            orderInfo.ostatus = object.getString("ostatus");
            orderInfo.receive_type = object.getString("receive_type");
            orderInfo.real_money = object.getString("real_money");
            orderInfo.productInfos = ProductInfo.parse(object.getJSONArray("products"));
            orderInfo.s_key = object.getString("s_key");
            orderInfos.add(orderInfo);
        }
        return orderInfos;
    }

    public static OrderDetail parse(JSONObject object) throws JSONException {
        if (object == null){
            return null;
        }
        OrderDetail orderInfo = new OrderDetail();
        orderInfo.sn = object.getString("sn");
        orderInfo.create_at = object.getString("create_at");
        orderInfo.receiver_name = object.getString("receiver_name");
        orderInfo.receiver_add = object.getString("receiver_add");
        orderInfo.receiver_tel = object.getString("receiver_tel");
        orderInfo.pay_type = object.getString("pay_type");
        orderInfo.cpucbt = object.getString("cpucbt");
        orderInfo.money = object.getDouble("money");
        orderInfo.notes = object.getString("notes");
        orderInfo.ostatus = object.getString("ostatus");
        orderInfo.receive_type = object.getString("receive_type");
        orderInfo.real_money = object.getString("real_money");
        orderInfo.productInfos = ProductInfo.parse(object.getJSONArray("products"));
        orderInfo.s_key = object.getString("s_key");

        return orderInfo;

    }
}
